﻿//-----------------------------------------------------------------
//
// @(#)$Id: PPDictionary.aspx.cs,v 1.0 2013/12/13 17:32:33 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:32:33 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using ebay.Dal.CenterDB_BasTableAdapters;
using ebay.Dal.CenterDB_EbayTableAdapters;

public partial class UI_Bas_PPDictionary : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        T_PayPalAccountTableAdapter ppAdapter = new T_PayPalAccountTableAdapter();
        ddlebayuserId.DataSource = ppAdapter.GetData();
        ddlebayuserId.DataTextField = "PayPalUserId";
        ddlebayuserId.DataValueField = "PayPalUserId";
        ddlebayuserId.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        WebUtility.CheckRight();
        if (!IsPostBack)
        {
            string ebayUserId = ddlebayuserId.Value;
            BindText(ebayUserId);
        }

    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        string ebayUserId = ddlebayuserId.Value;
        Reset();
        BindText(ebayUserId);
    }

    void Reset()
    {
        foreach (Control c in form1.Controls)
        {
            if (c is HtmlInputText)
            {
                ((HtmlInputText)c).Value = "";
            }
        }
    }
    void BindText(string ebayUserId)
    {
        if (!string.IsNullOrEmpty(ebayUserId))
        {
            txtEbayUserId.Value = ebayUserId;
            T_PPDictionaryTableAdapter ppAdapter = new T_PPDictionaryTableAdapter();
            DataTable table = ppAdapter.GetDataByEbayUserId(ebayUserId);
            if (table.Rows.Count == 0)
            {
                txtAddressLine1.Value = "Address Line 1";
                txtAddressLine2orDistrictorNeighbourhood.Value = "Address Line 2/District/Neighbourhood";
                txtAddressStatus.Value = "Address Status";
                txtAuctionSite.Value = "Auction Site";
                txtBalance.Value = "Balance";
                txtBalanceImpact.Value = "Balance Impact";
                txtBuyerID.Value = "Buyer ID";
                txtClosingDate.Value = "Closing Date";
                txtContactPhoneNumber.Value = "Contact Phone Number";
                txtCounterpartyStatus.Value = "Counterparty Status";
                txtCountry.Value = "Country";
                txtCurrency.Value = "Currency";
                txtCustomNumber.Value = "Custom Number";
                txtDate.Value = "Date";
                txtFee.Value = "Fee";
                txtFromEmailAddress.Value = "From Email Address";
                txtGross.Value = "Gross";
                txtInsuranceAmount.Value = "Insurance Amount";
                txtInvoiceNumber.Value = "Invoice Number";
                txtItemID.Value = "Item ID";
                txtItemTitle.Value = "Item Title";
                txtItemURL.Value = "Item URL";
                txtName.Value = "Name";
                txtNet.Value = "Net";
                txtNote.Value = "Note";
                txtOption1Name.Value = "Option 1 Name";
                txtOption1Value.Value = "Option 1 Value";
                txtOption2Name.Value = "Option 2 Name";
                txtOption2Value.Value = "Option 2 Value";
                txtPaymentType.Value = "Payment Type";
                txtPostageandPackingAmount.Value = "Postage and Packing Amount";
                txtPostalAddress.Value = "Postal Address";
                txtPostcode.Value = "Postcode";
                txtReceiptID.Value = "Receipt ID";
                txtReferenceTxnID.Value = "Reference Txn ID";
                txtReserve.Value = "Reserve";
                txtStateorProvinceorRegionorCountyorTerritoryorPrefectureorRepublic.Value = "State/Province/Region/County/Territory/Prefecture/Republic";
                txtStatus.Value = "Status";
                txtSubject.Value = "Subject";
                txtSubscriptionNumber.Value = "Subscription Number";
                txtTime.Value = "Time";
                txtTimeZone.Value = "Time Zone";
                txtToEmailAddress.Value = "To Email Address";
                txtTownorCity.Value = "Town/City";
                txtTransactionID.Value = "Transaction ID";
                txtType.Value = "Type";
                txtVAT.Value = "VAT";
            }
            else
            {
                foreach (DataRow r in table.Rows)
                {
                    string key = r[1].ToString();
                    string value = r[2].ToString();
                    switch (key)
                    {
                        case "Address Line 1":
                            txtAddressLine1.Value = value;
                            break;
                        case "Address Line 2/District/Neighbourhood":
                            txtAddressLine2orDistrictorNeighbourhood.Value = value;
                            break;
                        case "Address Status":
                            txtAddressStatus.Value = value;
                            break;
                        case "Auction Site":
                            txtAuctionSite.Value = value;
                            break;
                        case "Balance":
                            txtBalance.Value = value;
                            break;
                        case "Balance Impact":
                            txtBalanceImpact.Value = value;
                            break;
                        case "Buyer ID":
                            txtBuyerID.Value = value;
                            break;
                        case "Closing Date":
                            txtClosingDate.Value = value;
                            break;
                        case "Contact Phone Number":
                            txtContactPhoneNumber.Value = value;
                            break;
                        case "Counterparty Status":
                            txtCounterpartyStatus.Value = value;
                            break;
                        case "Country":
                            txtCountry.Value = value;
                            break;
                        case "Currency":
                            txtCurrency.Value = value;
                            break;
                        case "Custom Number":
                            txtCustomNumber.Value = value;
                            break;
                        case "Date":
                            txtDate.Value = value;
                            break;
                        case "Fee":
                            txtFee.Value = value;
                            break;
                        case "From Email Address":
                            txtFromEmailAddress.Value = value;
                            break;
                        case "Gross":
                            txtGross.Value = value;
                            break;
                        case "Insurance Amount":
                            txtInsuranceAmount.Value = value;
                            break;
                        case "Invoice Number":
                            txtInvoiceNumber.Value = value;
                            break;
                        case "Item ID":
                            txtItemID.Value = value;
                            break;
                        case "Item Title":
                            txtItemTitle.Value = value;
                            break;
                        case "Item URL":
                            txtItemURL.Value = value;
                            break;
                        case "Name":
                            txtName.Value = value;
                            break;
                        case "Net":
                            txtNet.Value = value;
                            break;
                        case "Note":
                            txtNote.Value = value;
                            break;
                        case "Option 1 Name":
                            txtOption1Name.Value = value;
                            break;
                        case "Option 1 Value":
                            txtOption1Value.Value = value;
                            break;
                        case "Option 2 Name":
                            txtOption2Name.Value = value;
                            break;
                        case "Option 2 Value":
                            txtOption2Value.Value = value;
                            break;
                        case "Payment Type":
                            txtPaymentType.Value = value;
                            break;
                        case "Postage and Packing Amount":
                            txtPostageandPackingAmount.Value = value;
                            break;
                        case "Postal Address":
                            txtPostalAddress.Value = value;
                            break;
                        case "Postcode":
                            txtPostcode.Value = value;
                            break;
                        case "Receipt ID":
                            txtReceiptID.Value = value;
                            break;
                        case "Reference Txn ID":
                            txtReferenceTxnID.Value = value;
                            break;
                        case "Reserve":
                            txtReserve.Value = value;
                            break;
                        case "State/Province/Region/County/Territory/Prefecture/Republic":
                            txtStateorProvinceorRegionorCountyorTerritoryorPrefectureorRepublic.Value = value;
                            break;
                        case "Status":
                            txtStatus.Value = value;
                            break;
                        case "Subject":
                            txtSubject.Value = value;
                            break;
                        case "Subscription Number":
                            txtSubscriptionNumber.Value = value;
                            break;
                        case "Time":
                            txtTime.Value = value;
                            break;
                        case "Time Zone":
                            txtTimeZone.Value = value;
                            break;
                        case "To Email Address":
                            txtToEmailAddress.Value = value;
                            break;
                        case "Town/City":
                            txtTownorCity.Value = value;
                            break;
                        case "Transaction ID":
                            txtTransactionID.Value = value;
                            break;
                        case "Type":
                            txtType.Value = value;
                            break;
                        case "VAT":
                            txtVAT.Value = value;
                            break;
                    }
                }
            }
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string ebayUserId = txtEbayUserId.Value;
        if (string.IsNullOrEmpty(ebayUserId))
        {
            WebUtility.ShowMsg("还未选择ebay帐号", this);

            return;
        }

        List<ebay.Model.PPDictionary> list = new List<ebay.Model.PPDictionary>();

        foreach (Control c in form1.Controls)
        {
            if (c is HtmlInputText)
            {
                HtmlInputText htmlTxtControl=(HtmlInputText)c;
                ebay.Model.PPDictionary m = new ebay.Model.PPDictionary();
                m.CValue = htmlTxtControl.Value;
                m.EbayUserId = txtEbayUserId.Value;
                string Id = c.ID;
                switch (Id)
                {
                    case "txtAddressLine1":
                        m.CKey = "Address Line 1";
                        break;
                    case "txtAddressLine2orDistrictorNeighbourhood":
                        m.CKey = "Address Line 2/District/Neighbourhood";
                        break;
                    case "txtAddressStatus":
                        m.CKey = "Address Status";
                        break;
                    case "txtAuctionSite":
                        m.CKey = "Auction Site";
                        break;
                    case "txtBalance":
                        m.CKey = "Balance";
                        break;
                    case "txtBalanceImpact":
                        m.CKey = "Balance Impact";
                        break;
                    case "txtBuyerID":
                        m.CKey = "Buyer ID";
                        break;
                    case "txtClosingDate":
                        m.CKey = "Closing Date";
                        break;
                    case "txtContactPhoneNumber":
                        m.CKey = "Contact Phone Number";
                        break;
                    case "txtCounterpartyStatus":
                        m.CKey = "Counterparty Status";
                        break;
                    case "txtCountry":
                        m.CKey = "Country";
                        break;
                    case "txtCurrency":
                        m.CKey = "Currency";
                        break;
                    case "txtCustomNumber":
                        m.CKey = "Custom Number";
                        break;
                    case "txtDate":
                        m.CKey = "Date";
                        break;
                    case "txtFee":
                        m.CKey = "Fee";
                        break;
                    case "txtFromEmailAddress":
                        m.CKey = "From Email Address";
                        break;
                    case "txtGross":
                        m.CKey = "Gross";
                        break;
                    case "txtInsuranceAmount":
                        m.CKey = "Insurance Amount";
                        break;
                    case "txtInvoiceNumber":
                        m.CKey = "Invoice Number";
                        break;
                    case "txtItemID":
                        m.CKey = "Item ID";
                        break;
                    case "txtItemTitle":
                        m.CKey = "Item Title";
                        break;
                    case "txtItemURL":
                        m.CKey = "Item URL";
                        break;
                    case "txtName":
                        m.CKey = "Name";
                        break;
                    case "txtNet":
                        m.CKey = "Net";
                        break;
                    case "txtNote":
                        m.CKey = "Note";
                        break;
                    case "txtOption1Name":
                        m.CKey = "Option 1 Name";
                        break;
                    case "txtOption1Value":
                        m.CKey = "Option 1 Value";
                        break;
                    case "txtOption2Name":
                        m.CKey = "Option 2 Name";
                        break;
                    case "txtOption2Value":
                        m.CKey = "Option 2 Value";
                        break;
                    case "txtPaymentType":
                        m.CKey = "Payment Type";
                        break;
                    case "txtPostageandPackingAmount":
                        m.CKey = "Postage and Packing Amount";
                        break;
                    case "txtPostalAddress":
                        m.CKey = "Postal Address";
                        break;
                    case "txtPostcode":
                        m.CKey = "Postcode";
                        break;
                    case "txtReceiptID":
                        m.CKey = "Receipt ID";
                        break;
                    case "txtReferenceTxnID":
                        m.CKey = "Reference Txn ID";
                        break;
                    case "txtReserve":
                        m.CKey = "Reserve";
                        break;
                    case "txtStateorProvinceorRegionorCountyorTerritoryorPrefectureorRepublic":
                        m.CKey = "State/Province/Region/County/Territory/Prefecture/Republic";
                        break;
                    case "txtStatus":
                        m.CKey = "Status";
                        break;
                    case "txtSubject":
                        m.CKey = "Subject";
                        break;
                    case "txtSubscriptionNumber":
                        m.CKey = "Subscription Number";
                        break;
                    case "txtTime":
                        m.CKey = "Time";
                        break;
                    case "txtTimeZone":
                        m.CKey = "Time Zone";
                        break;
                    case "txtToEmailAddress":
                        m.CKey = "To Email Address";
                        break;
                    case "txtTownorCity":
                        m.CKey = "Town/City";
                        break;
                    case "txtTransactionID":
                        m.CKey = "Transaction ID";
                        break;
                    case "txtType":
                        m.CKey = "Type";
                        break;
                    case "txtVAT":
                        m.CKey = "VAT";
                        break;
                }
                list.Add(m);
            }
        }
        ebay.Dal.PPDictionary p = new ebay.Dal.PPDictionary();
        p.Add(list, ebayUserId);
        WebUtility.ShowMsg("操作成功", this);
    }
}
